package com.example.hellodemo.listView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.hellodemo.R;

public class MyListAdapter extends BaseAdapter { // 适配器，用来做布局视图的代理

    private  Context mContent;
    private LayoutInflater mLayoutInflater;
    public MyListAdapter(Context context){
        this.mContent = context;
        mLayoutInflater = LayoutInflater.from(context); // 得到布局管理器
    }
    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    // 内部函数 作用用来 指向所对应的布局，然后快捷调用处理
    static class ViewHolder{
        public ImageView imageView;
        public TextView tvTitle,tvTime,tvContent;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = mLayoutInflater.inflate(R.layout.list_item,null); //// 布局管理器 获取view
            holder = new ViewHolder();
            holder.imageView = convertView.findViewById(R.id.imgView);
            holder.tvTitle = convertView.findViewById(R.id.text1);
            holder.tvTime = convertView.findViewById(R.id.text2);
            holder.tvContent = convertView.findViewById(R.id.text3);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvTitle.setText("星空Tivoli");
        holder.tvTime.setText("2010-23-23");
        holder.tvContent.setText("测试得am的");
        Glide.with(mContent).load("https://www.baidu.com/img/bd_logo1.png?where=super").into(holder.imageView);
        return convertView;
    }
}
